const mongoose = require('mongoose')
const bcrypt = require('bcryptjs')
const { Schema, model } = mongoose

// const Schema = mongoose.Schema
// const model = mongoose.model
const UserSchema = new Schema({
    username: { type:String, require:true},
    password: {
        type:String,
        require:true,
        // 这里是密码加密处理
        // 10为加密等级，在登录路由也要用到bcrypt解密校验判断
        // set (val) {
        //     return bcrypt.hashSync(val, 10)
        // }
    },
    name: { type:String, require:true},
    idiograph: {type:String},
    picture: {type:String},
    isAdmin: { type:String, default:'0' } // 身份 1 ->管理员， 0 -> 普通用户
})
const User = model('user', UserSchema)
module.exports = User
